package com.frejoys.common.util;

import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.frejoys.common.config.ValueConfig;
import jakarta.annotation.PostConstruct;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

/**
 * 阿里云oss
 */
@Component
@RequiredArgsConstructor
public class OssUtil {

    public final ValueConfig valueConfig;

    public static OSS ossClient;

    @PostConstruct
    private void init() {

        // 使用自定义域名，endpoint填写为自定义域名
        ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
        conf.setSupportCname(true);

        ossClient = new OSSClientBuilder().build(valueConfig.getAliOssBucketUploadUrl(), valueConfig.getAliOssBucketUploadAccessKeyID(), valueConfig.getAliOssBucketUploadAccessKeySecret(), conf);
    }

}
